<template>
	<view class="addpay">
		<view class="tip">
			账户正在保护，请放心添加
		</view>
		<view class="black_1">
			<view class="text1">
				支付类型
			</view>
			<view class="text2">{{name}}</view>
		</view>

		 <view class="black_2">
			<view class="text1">
				{{info.type == 'usdt' ?"通道": "姓名"}}
			</view>
			<view class="text2" v-if="info.type == 'usdt'" @click="iconClick()">{{info.data.real_name}}</view>
			<uni-easyinput v-else :input-border="false" v-model="info.data.real_name" placeholder="请输入名字"
				placeholder-style="font-size: 25rpx;" />
		</view>
<view class="black_2" v-if="info.type =='rmb'">
			<view class="text1">
				银行名称
			</view>
			<uni-easyinput :input-border="false" v-model="info.data.bank_name"
				placeholder="请输入银行名称"
				:styles="{backgroundColor: 'transparent'}" placeholder-style="font-size: 25rpx;" />
		</view> 
		<view class="black_2">
			<view class="text1">
				{{info.type == 'usdt' ?"地址钱包": info.type == 'bank'?"银行卡号":  info.type == 'rmb'?'钱包编号':"账户"}}
			</view>
			<uni-easyinput :input-border="false" v-model="info.data.account_name"
				:placeholder="info.type == 'usdt' ?'请输入地址钱包': info.type == 'bank'?'请输入银行卡号':info.type == 'rmb'?'请输入钱包编号':'请输入账户' "
				:styles="{backgroundColor: 'transparent'}" placeholder-style="font-size: 25rpx;" />
		</view> 
		<view class="black_2" v-if="info.type =='bank'">
			<view class="text1">
				银行名称
			</view>
			<uni-easyinput :input-border="false" v-model="info.data.bank_name"
				placeholder="请输入银行名称"
				:styles="{backgroundColor: 'transparent'}" placeholder-style="font-size: 25rpx;" />
		</view> 
		<view class="black_3" v-if="info.type !='bank' && info.type !='rmb'">
			<view class="text1">
				{{info.type == 'usdt'?'地址截图':'收款码'}}
			</view>
			<image class="img" :src="info.data.image" @click="chooseImage()"></image>
		</view>

		<view class="black_4" @click="submit()">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				images: '../../static/my/add_tu.png',
				info: {
					"id": 0,
					"user_id": 0,
					"type": "wechat",
					"network": null,
					"data": {
						"real_name": "",
						"account_name": "",
						"image": "../../static/my/add_tu.png"
					},
				},
				network: 'BNB',
				name: '',
				isEdt:0,
				waySuccsse:0
			};
		},
		onLoad(opt) {
			console.log(1111, opt.name)
			this.name = opt.name;
			this.info.type = opt.type;
			this.isEdt = opt.isEdt
			if (this.info.type == 'usdt') {
				if(opt.network){
					this.info.data.real_name = opt.network
				}else{
				this.info.data.real_name = "BNB"
				}
				
			}
			// if(this.info.type == 'ysf'){
			// 	this.name="手机号"
			// }
			var that = this
			uni.$on('waySuccsse', function(data) {
				that.info.data.real_name = data
				that.waySuccsse = 1
			})

		},
		onShow() {
			this.getInfo()
		},
		methods: {
			getInfo() {
				if(this.isEdt == 0){
					return
				}
				var that = this
				let data = {
					type: this.info.type,
					network: this.info.data.real_name
				};
				this.api.http.requests('exchangecollection/info', data, res => {

					if (res.data) {

						if (that.info.type == 'usdt') {
							var isMore = false
							res.data.forEach((item, index) => {
								if (item.network === that.info.data.real_name) {
									// that.info.data = item
									that.info.id = item.id
									that.info.network = item.network
									that.info.type = item.type
									that.info.user_id = item.user_id
									that.info.data.real_name = item.data.network
									that.info.data.image = item.data.image
									that.info.data.account_name = item.data.money_address
									isMore = true
									return
								}
							})
							if(isMore)
								return
							if(that.isEdt == 1 && that.waySuccsse == 1){
								that.info.id = 0
								// that.info.network = item.network
								that.info.type = 'usdt'
								that.info.user_id = 0
								// that.info.data.real_name = item.data.network
								that.info.data.image = "../../static/my/add_tu.png"
								that.info.data.account_name = ""
								return
							}
							var item = res.data[0]
							that.info.id = item.id
							that.info.network = item.network
							that.info.type = item.type
							that.info.user_id = item.user_id
							that.info.data.real_name = item.data.network
							that.info.data.image = item.data.image
							that.info.data.account_name = item.data.money_address
						} else {
							that.info = res.data
							if (that.info.type == 'bank' || that.info.type == 'rmb') {
								that.info.data.account_name = res.data.data.bank_number
							} else if (that.info.type == 'ysf') {
								that.info.data.account_name = res.data.data.phone
							}
						}

					}
				}, "POST")

			},
			iconClick() {
				this.custom.tool.jump(0, 'my/selecttongdao?type=' + this.info.data.real_name)
			},
			chooseImage() {
				var that = this
				// 调用手机相机和获取相册功能
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.http.upload(tempFilePaths[0], {}, res => {
							console.log(res)
							if (res.data) {
								that.info.data.image = 'http://zygq.opo5.com' + res.data
							}
						});
					}
				});
			},
			submit() {
				if (!this.info.data.real_name) {
					this.custom.tool.showToast("名字不能为空")
					return
				}
				if (!this.info.data.account_name) {
					this.custom.tool.showToast("帐号不能空")
					return
				}
				if (this.info.type != 'rmb' && this.info.type != 'bank' && this.info.type != 'ysf') {
					if (this.info.data.image == '../../static/my/add_tu.png') {
						this.custom.tool.showToast("请上传图片")
						return
					}
				}
				if ((this.info.type == 'bank' && this.info.type != 'rmb') && !this.info.data.bank_name) {
					this.custom.tool.showToast("银行名称不能为空")
					return
				}
				var datas = {
					type: this.info.type,
				}

				if (this.info.type == 'bank' || this.info.type == 'rmb') {
					datas.bank_number = this.info.data.account_name
					datas.bank_name = this.info.data.bank_name
					datas.real_name = this.info.data.real_name
				} else {


					if (this.info.type == 'ysf') {
						datas.phone = this.info.data.account_name
						datas.real_name = this.info.data.real_name
					} else if (this.info.type == 'usdt') {
						var url = this.info.data.image.replace('http://zygq.opo5.com', '')
						datas.money_address = this.info.data.account_name
						datas.network = this.info.data.real_name
						datas.image = url
					} else {
						var url = this.info.data.image.replace('http://zygq.opo5.com', '')
						datas.account_name = this.info.data.account_name
						datas.real_name = this.info.data.real_name
						datas.image = url
					}
				}

				this.api.http.requests('exchangecollection/edit', datas, res => {

					uni.showToast({
						title: res.msg,
						success: function() {
							setTimeout(function() {
								//要延时执行的代码
								uni.navigateBack()
							}, 3000) //延迟时间 
						}
					})


				}, "POST")
			}

		}
	}
</script>
<style>
	page {
		background-color: white;
	}
</style>
<style lang="less">
	.tip {
		background: #FFFBC8;
		font-size: 30rpx;
		font-weight: 400;
		color: #FE903D;
		padding: 10px;
		margin-bottom: 20px;
	}

	.black_1,
	.black_2,
	.black_3 {
		display: flex;
		padding: 10px 15px;
		border-bottom: 1px solid #ECECEC;
		align-items: center;
		font-size: 16px;
		color: #333333;

		.text1 {
			width: 70px;
		}

		.text2 {
			margin-left: 10px;
		}

		.img {
			margin-left: 10px;
			width: 80px;
			height: 80px;
		}
	}


	.black_4 {
		background-color: #FE903D;
		border-radius: 5px;
		font-size: 35rpx;
		font-weight: 400;
		padding: 10px 0px;
		color: #FFFFFF;
		text-align: center;
		margin: 100px 20px 20px 20px;
	}
</style>